package com.cuit.xsc.weishare.activity;



import com.cuit.xsc.weishare.R;
import com.cuit.xsc.weishare.logic.MainService;
import com.cuit.xsc.weishare.util.LogUtil;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class BaseActivity extends Activity
{
	private TextView waitingDialogMessage;
	
	protected AlertDialog waitingDialog;
	protected ProgressDialog progress;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);	
        super.onCreate(savedInstanceState);
        MainService.allActivity.add(this);
	}
	
	 public void refresh(Object ...param)
	 {
		 
	 }
	 
	 protected void showWaitingDialog(String message)
	{
		 LogUtil.d(this, "showWaitingDialog");
		 LogUtil.d(this, "" + this);
		if (waitingDialog == null)
		{
			waitingDialog = new AlertDialog.Builder(this).create();
			LayoutInflater inflater = LayoutInflater.from(this);
			View view = inflater.inflate(R.layout.waitingdialog, null);
			waitingDialogMessage = (TextView) view.findViewById(R.id.waitingdialog_tv);
			getWindow().setContentView(view);

		}
		
		

		if (waitingDialog.isShowing())
		{
			waitingDialogMessage.setText(message);
		} else
		{
			waitingDialog.show();
			waitingDialogMessage.setText(message);
		}

	}
	 
	 protected void showWaitingDialog(int id)
	 {
		 String message = getResources().getString(id);
		 showWaitingDialog(message);
	 }
	 
	 
	 protected void dismissWaitingDialog()
	 {
		 LogUtil.d(this, "dismissWaitingDialog");
		 LogUtil.d(this, "" + this);
		 if (waitingDialog.isShowing())
		{
			 LogUtil.d(this, "dismiss");
			waitingDialog.dismiss();
		}
	 }
	 
	 public void showProgress(){
	    	if(null == progress){
				progress = new ProgressDialog(this);
				progress.setMessage("please wait");
				progress.setCancelable(true);
			}
			progress.show();
			
			//LogUtil.d(this, progress + " "+ progress.isShowing());
		}
	 
	 public void dismissProgress()
	 {
		 LogUtil.d(this, "progress " + progress);
		 LogUtil.d(this, progress.isShowing()+ "" + this);
			if(null!=progress)
			{
		    	progress.dismiss();
		    //	LogUtil.d(this, "progress.dismiss");
		    }
		}
	 
	 
	 @Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		 if(keyCode == KeyEvent.KEYCODE_BACK)
		 {
			//LogUtil.d(this, "back "+this.getClass().getSimpleName()); 
		 }
		return super.onKeyDown(keyCode, event);
	}
	 
	 
	 @Override
	protected void onDestroy()
	{
		// LogUtil.d(this, this+" onDestroy");
		String className =  this.getClass().getSimpleName();
		MainService.removeActivityByName(className);
		super.onDestroy();
	}

}
